package edu.stonybrook.cs.gars.shared.users;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

/**
 * @author Tony Arra & Peter Iannone
 * Represents a single user of the GARS system
 */

public class User implements Serializable 
{
	int numAssignedReviews;
	float workload;
	boolean available;
	String password;
	String username;
	String email;
	List<String> countries;
	Vector<Subject> fields;
	Role role;
	
	public User(){}
	
	/**
	 * Constructs a new user
	 * 
	 * @param email
	 * @param role
	 */
	public User(String username, String password, Role role,
			int numAssignedReviews, float workload, boolean available,
			String email, List<String> countries, Vector<Subject> fields) {
		this.fields = new Vector<Subject>();
		this.username = username;
		this.password = password;
		this.role = role;
		this.numAssignedReviews = numAssignedReviews;
		this.workload = workload;
		this.available = available;
		this.email = email;
		this.countries = countries;
		this.fields = fields;

	}

	// Accessors
	public String getUsername() {
		return username;
	}

	public Role getRole() {
		return role;
	}

	public static Role roleStringToEnum(String string) {
		if (string.equals(Role.CHAIR.toString()))
			return Role.CHAIR;
		if (string.equals(Role.FACULTY.toString()))
			return Role.FACULTY;
		if (string.equals(Role.STAFF.toString()))
			return Role.STAFF;

		return null;
	}

	public static Vector<Subject> fieldsStringListToFieldsEnumVector(
			List<String> fieldsStringList) {
		Vector<Subject> fieldsEnumVector = new Vector<Subject>();

		Iterator<String> it = fieldsStringList.iterator();
		while (it.hasNext())
			fieldsEnumVector.add(subjectStringToEnum(it.next()));

		return fieldsEnumVector;
	}

	public static Subject subjectStringToEnum(String string) {
		if (string.equals(Subject.AI.toString()))
			return Subject.AI;
		if (string.equals(Subject.GV.toString()))
			return Subject.GV;
		if (string.equals(Subject.NET.toString()))
			return Subject.NET;
		if (string.equals(Subject.PLV.toString()))
			return Subject.PLV;
		if (string.equals(Subject.STY.toString()))
			return Subject.STY;
		if (string.equals(Subject.SYS.toString()))
			return Subject.SYS;
		if (string.equals(Subject.THY.toString()))
			return Subject.THY;
		if (string.equals(Subject.NLP.toString()))
			return Subject.NLP;
		return null;
	}
}
